{% extends 'layout.html.twig' %}

{% block container %}
    {% if bill.letra == 'A' %}
        {% set img_bill = 'FCA.jpg' %}
    {% elseif bill.letra == 'B' %}
        {% set img_bill = 'FCB.jpg' %}
    {% elseif bill.letra == 'X' %}
        {% set img_bill = 'FCX.jpg' %}
    {% endif %}
    <div class="row">
        <table align="center" width="724" height="1050" border="0" cellpadding="0" cellspacing="0" background="{{ asset(origin ~ '/img/' ~ img_bill) }}">
            <thead>
            <tr>
                <td height="16" colspan="6">&nbsp;</td>
                <td colspan="2">&nbsp;</td>
                <td class="vert-align">&nbsp;</td>
            </tr>
            <tr>
                <td height="24" colspan="6">&nbsp;</td>
                <td colspan="2">&nbsp;</td>
                <td width="137" class="vert-align">{{ bill.numero }}</td>
            </tr>
            <tr>
                <td height="36" colspan="7">&nbsp;</td>
                <td colspan="1">{{ bill.fecha|date('d/m/Y') }}</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td height="109" colspan="6">&nbsp;</td>
                <td colspan="2">&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td width="74" height="87">&nbsp;</td>
                <td colspan="3">
                    {{ bill.razon }}<br/>
                    {{ bill.domicilio }}<br/>
                    {{ bill.localidad }}
                </td>
                <td colspan="5">
                    Cuenta: {{ bill.codigoe }}<br/>
                    CUIT: {{ bill.nrocuit }}
                </td>
            </tr>
            <tr>
                <td height="41">&nbsp;</td>
                <td colspan="5">Contado</td>
                <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
                <td height="37" class="text-center">Cantidad</td>
                <td colspan="5">Descripción</td>
                <td colspan="2">Precio</td>
                <td>Total</td>
            </tr>
            </thead>
            <tbody>
            {% for i in 0..16 %}
            <tr>
                <td height="26" class="text-center">
                    {% if rows[i] is defined %}
                        {{ rows[i].cantidad }}
                    {% endif %}
                </td>
                <td colspan="5">
                    {% if rows[i] is defined %}
                        {{ rows[i].descripcion }}
                    {% endif %}
                </td>
                <td colspan="2">
                    {% if rows[i] is defined %}
                        {{ rows[i].precio|number_format(2, ',', '.') }}
                    {% endif %}
                </td>
                <td>
                    {% if rows[i] is defined %}
                        {{ rows[i].total|number_format(2, ',', '.') }}
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
            </tbody>
            <tfoot>
            <tr>
                <td height="42" class="text-center"></td>
                <td colspan="5"></td>
                <td colspan="2"></td>
                <td></td>
            </tr>
            <tr>
                <td height="65">&nbsp;</td>
                <td colspan="5">&nbsp;</td>
                {% if bill.letra != 'X' %}
                    <td colspan="2">Percepcion: {{ bill.porceper }}</td>
                    <td>{{ bill.impoper }}</td>
                {% else %}
                    <td colspan="3"></td>
                {% endif %}
            </tr>
            <tr>
                <td height="23">&nbsp;</td>
                <td width="61">&nbsp;</td>
                <td width="130">&nbsp;</td>
                <td width="99">&nbsp;</td>
                <td width="11">&nbsp;</td>
                <td width="21">&nbsp;</td>
                <td width="123">&nbsp;</td>
                <td width="70">&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td height="37" colspan="2" class="text-center">{{ bill.gravado|number_format(2, ',', '.') }}</td>
                {% set noGravado = (bill.nogravado < 1) ? 0 : bill.nogravado %}
                <td class="text-center">{{ noGravado|number_format(2, ',', '.') }}</td>
                <td colspan="2" class="text-center">{{ bill.subtotal|number_format(2, ',', '.') }}</td>
                <td colspan="2" class="text-center">{{ bill.iva1|number_format(2, ',', '.') }}</td>
                <td colspan="2" class="text-center">{{ bill.total|number_format(2, ',', '.') }}</td>
            </tr>
            <tr>
                <td height="53" colspan="9">&nbsp;</td>
            </tr>
            </tfoot>
        </table>
        <hr/>
        <table class="table table-striped">
            <caption>Prestaciones Facturadas.</caption>
            <thead>
                <tr>
                    <th>Fecha</th>
                    <th>Nombre</th>
                    <th>Estudio</th>
                    <th>Cantidad</th>
                    <th>Precio</th>
                </tr>
            </thead>
            <tbody>
            {% for row in services %}
                <tr>
                    <td>{{ row.fecha|date('d/m/Y') }}</td>
                    <td>{{ row.nombre }}</td>
                    <td>{{ row.estudio }}</td>
                    <td>{{ row.cantidad }}</td>
                    <td>{{ row.precio|number_format(2, ',', '.') }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock container %}